<template>
	<scroll-view class="listview" style="background-color: #F4F4F4; " >
		<view class="itemClass" v-for="(item,index) in allDataArray.msg" :key="index" @tap.stop="cellClick(item.goods.id)">
			<image class="iconImage"  :src="item.goods.goods_image" ></image>
			<view style="flex-wrap: wrap;">
				<view class="titile_class">{{item.goods.goods_name}}</view>
				<view style="display: flex; position: relative;top: 32rpx;">
					<view class="price_class" style="padding-left: 32rpx; color: #F25F5F;">¥{{item.goods.goods_price}}</view>
					<image class="shouchang_icon" @tap.stop="shouchang(index,item.goods_id)" src="../../../static/img/shouchang/xuanzhong_shouchang.png" ></image>
				</view>
			</view>
		</view>
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				allDataArray : [],
				page:1,
				userInfo:"",
			}
		},
		onLoad: function (options) {    
			this.userInfo = uni.getStorageSync('userInfo'); // 同步获取本地数据
			if(this.userInfo.token){
				setTimeout(function () {
				}, 1000);
				uni.startPullDownRefresh();
			}else{
				uni.navigateTo({
					url: "../login/login",
				})
			}
		},
		//下拉刷新
		onPullDownRefresh() {
			this.userInfo = uni.getStorageSync('userInfo'); // 同步获取本地数据
			if(this.userInfo.token){
				this.page=1;
				this.loadAllDataNetworking();
				setTimeout(function () {
				    uni.stopPullDownRefresh();
				}, 1000);
			}else{
				uni.stopPullDownRefresh();
				uni.navigateTo({
					url: "../login/login",
				})
			}
		},
		// 上拉加载
		onReachBottom() {
			// if(!this.isLoadMore){  //此处判断，上锁，防止重复请求
			// 	this.isLoadMore=true
				this.page+=1
			// }
			this.loadAllDataNetworking();			
		},
		methods: {
			shouchang(index,id){
				this.cancelCollectionNetworking(id);
			},
			cellClick(id){
				uni.navigateTo({
					url: "../tabbar-1/commodity-details/index?id="+id,
				})
			},
			
			loadAllDataNetworking(){
				uni.request({
					url:this.baseurl+"index.php/api/index/collectList",
					header:{
						"token":this.userInfo.token,
					},
					data:{
						"page":this.page,
						"page_num":"10",
					},
					success:(res)=>{
						if(1==this.page){
							this.allDataArray = res.data;
						}else{
							var data = res.data;
							this.allDataArray.msg.concat(data.msg);
						}
					}
				})
			},
			cancelCollectionNetworking(goods_id){
				uni.request({
					url:this.baseurl+"index.php/api/index/userCollect",
					header:{
						"token":this.userInfo.token,
					},
					data:{
						"goods_id":goods_id,
						"is_collect":"0",
					},
					success:(res)=>{
						if("1"==res.data.code){
							uni.showToast({
							    title: "取消收藏",
								mask:true,
								position:"center",
							    duration: 2000
							});
							this.loadAllDataNetworking();
						}
					}
				})
			}	
		}
	}
</script>

<style>

	.listview{
		
		
	}
	.itemClass{
		display: flex;
		padding: 32rpx;
		border-bottom: 1rpx dashed #979797;
		
	}
	.iconImage{
		height: 176rpx;
		width: 176rpx;
		/* margin: 32rpx 0rpx 32rpx 32rpx; */
	}
	.titile_class{
		/* padding: 32rpx; */
		margin-left: 32rpx;
		
		width: 478rpx;
	}
	.shouchang_icon{
		width: 48rpx;
		height: 44rpx;
		position: absolute;
		right: 32rpx;
	}
</style>
